package asteroids.model.programs.statement;

import java.util.ArrayList;
import java.util.Map;

import asteroids.model.programs.expression.*;
import asteroids.model.programs.type.*;

public class Print extends S {

	private E e;
	public Print(int line, int column, E e) {
		super(line, column);
		this.e = e;
	}
	
	@Override
	public void execute(T type) {
		e.getValue().print();
		setExecuted(true);
	}
	
	public boolean hasSteps(){
		return true;
	}
	
	public E getExpression(){
		return e;
	}
	
	public ArrayList<VariableExpression> getVariableExpressions(){
		return getExpression().getVariables();
	}

	@Override
	public ArrayList<E> getExpressions() {
		ArrayList<E> list = new ArrayList<E>();
		list.add(getExpression());
		return list;
	}
	
	public String typecheck(Map<String, T> globals){
		String eTypeCheck = getExpression().typecheck();
		if(!eTypeCheck.equals(""))
			return eTypeCheck;
		T type = getExpression().getValue();
		if(type != null && (type.getClass() == DoubleType.class || type.getClass() == Bool.class))
			return "";
		return "Typecast error at line " + getLine() + ", column " + getColumn() + ".\n";
	}
	
	public boolean hasAction(){
		return false;
	}
}
